package com.example.sys.auth.dao;

import com.example.core.dao.BaseCoreDao;
import com.example.sys.auth.po.SysAuth;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SysAuthDao extends BaseCoreDao<SysAuth> {

    @Select("<script>" + " select model_id from sys_auth where type = #{type} and model_name =#{modelName} and element_id in ( " + " <foreach collection='authIds' separator=',' item='id'>" + " #{id} " + " </foreach> " + " )</script>")
    public List<String> findModelIdList(@Param("type") String type, @Param("modelName") String modelName, @Param("authIds") List<String> authIds);

    @Select("<script>" + " select count(*) from sys_auth where type = #{type} and model_name =#{modelName} and model_id =#{modelId} and element_id in ( " + " <foreach collection='authIds' separator=',' item='id'>" + " #{id} " + " </foreach> " + " )</script>")
    public int findCount(@Param("type") String type, @Param("modelName") String modelName, @Param("modelId") String modelId, @Param("authIds") List<String> authIds);

    @Delete("delete from sys_auth where model_id =#{modelId}")
    public void deleteByModelId(@Param("modelId") String modelId);

    @Select("select * from sys_auth where model_name =#{modelName} and model_id =#{modelId} and type = #{type}")
    public List<SysAuth> findList(@Param("type") String type, @Param("modelName") String modelName, @Param("modelId") String modelId);
}
